/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


// Custom drop action for the country boxes
function dropItems(idOfDraggedItem,targetId,x,y)
{
    var targetObj = document.getElementById(targetId);	// Creating reference to target obj
    var subDivs = targetObj.getElementsByTagName('div'); // Number of subdivs
	
    /*    
    if(subDivs.length>0 && targetId!='capitals' && x != 1)
    {
        
        var f = document.getElementById(idOfDraggedItem);

        var g = f.childNodes;

        var h = g.item(1).getElementsByTagName('div')[1].innerText;


     
        var pp = subDivs.item(0).getAttribute('id');
        dropItems(pp,'capitals',1,0);
        
    }    
 	*/
    var sourceObj = document.getElementById(idOfDraggedItem);	// Creating reference to source, i.e. dragged object
	
   
    	// Target is the capital box - append the dragged item as child of first sub div, i.e. as child of <div id="dropContent">
    
    if(targetObj == 'capitals')
    {
        targetObj = targetObj.getElementsByTagName('div')[0];
        sourceObj.style.backgroundColor='';

        

    }
    else
    {
       
        
        
    }
    

        /*
        var ddd = sourceObj.childNodes;
        var eee = ddd.item(2).innerText;
       
        if(eee == '_QB1'){
            document.getElementById('myQB1').innerHTML="";

            ddd.item(2).innerText = '';
            
        }
        else if(eee=='_Wo1'){
            document.getElementById('myWo1').innerHTML="";
            ddd.item(2).innerText = '';
        }
        else if(eee=='_RB1'){
            document.getElementById('myRB1').innerHTML="";
            ddd.item(2).innerText = '';
        }
        else if(eee=='_RB2'){
            document.getElementById('myRB2').innerHTML="";
            ddd.item(2).innerText = '';
        }
        else if(eee=='_WR1'){
            document.getElementById('myWR1').innerHTML="";
            ddd.item(2).innerText = '';
        }
        else if(eee=='_WR2'){
            document.getElementById('myWR2').innerHTML="";
            ddd.item(2).innerText = '';
        }
        else if(eee=='_TE1'){
            document.getElementById('myTE1').innerHTML="";
            ddd.item(2).innerText = '';
        }
        else if(eee=='_KK1'){
            document.getElementById('myKK1').innerHTML="";
            ddd.item(2).innerText = '';
        }
        else if(eee=='_DEF'){
            document.getElementById('myDEF').innerHTML="";
            ddd.item(2).innerText = '';
        }
        
        */
       
   
    targetObj.appendChild(sourceObj);
        
    /*
    if(flag != 'F')
    {
        
        if(x != 1)
        {
            var e = document.getElementById(idOfDraggedItem);

            var d = e.childNodes;

            var c = d.item(1).getElementsByTagName('div')[1].innerText;
       
            if(targetId == '_QB1'){
                document.getElementById('myQB1').innerHTML="";
                document.getElementById('myQB1').innerHTML=c;
                d.item(2).innerText = '_QB1';
                
            }
            else if(targetId=='_Wo1'){
                document.getElementById('myWo1').innerHTML="";
                document.getElementById('myWo1').innerHTML=c;
                d.item(2).innerText = '_Wo1';
            }
            else if(targetId=='_RB1'){
                document.getElementById('myRB1').innerHTML="";
                document.getElementById('myRB1').innerHTML=c;
                d.item(2).innerText = '_RB1';
            }
            else if(targetId=='_RB2'){
                document.getElementById('myRB2').innerHTML="";
                document.getElementById('myRB2').innerHTML=c;
                d.item(2).innerText = '_RB2';
            }
            else if(targetId=='_WR1'){
                document.getElementById('myWR1').innerHTML="";
                document.getElementById('myWR1').innerHTML=c;
                d.item(2).innerText = '_WR1';
            }
            else if(targetId=='_WR2'){
                document.getElementById('myWR2').innerHTML="";
                document.getElementById('myWR2').innerHTML=c;
                d.item(2).innerText = '_WR2';
            }
            else if(targetId=='_TE1'){
                document.getElementById('myTE1').innerHTML="";
                document.getElementById('myTE1').innerHTML=c;
                d.item(2).innerText = '_TE1';
            }
            else if(targetId=='_KK1'){
                document.getElementById('myKK1').innerHTML="";
                document.getElementById('myKK1').innerHTML=c;
                d.item(2).innerText = '_KK1';
            }
            else if(targetId=='_DEF'){
                document.getElementById('myDEF').innerHTML="";
                document.getElementById('myDEF').innerHTML=c;
                d.item(2).innerText = '_DEF';
            }
        } 
        
    }*/
    
}



var dragDropObj = new DHTMLgoodies_dragDrop();	// Creating drag and drop object


$.each($('.dragableBox'), function() {
    
    var s = this.id;

    dragDropObj.addSource(s,true);
});


// Assigning drop events on the countries

dragDropObj.addTarget('_DR1','dropItems'); // Set <div id="leftColumn"> as a drop target. Call function dropItems on drop
dragDropObj.addTarget('capitals','dropItems'); // Set <div id="leftColumn"> as a drop target. Call function dropItems on drop

dragDropObj.init();	// Initizlizing drag and drop object

